<template>
  <div>
    <Switch v-model:checked="curValue" />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue'
import { Switch } from 'ant-design-vue'

export default defineComponent({
  name: 'BwDesignFilterTableComFilterSwitch',
  components: { Switch },
  props: {
    value: {
      type: [Boolean],
    },
  },
  emits: ['update:value'],
  setup(props, { emit }) {
    const curValue = ref<boolean>()
    watch(
      () => props.value,
      (newVal) => {
        curValue.value = newVal
      },
      { immediate: true }
    )
    watch(
      () => curValue.value,
      (newVal) => {
        if (props.value !== newVal) {
          emit('update:value', newVal)
        }
      }
    )

    return { curValue }
  },
})
</script>

<style scoped></style>
